package com.wunong.smart.address.service;

import com.wunong.smart.address.client.query.UserAddressQueryDTO;
import com.wunong.smart.address.client.dto.UserAddressDTO;
import com.wunong.smart.address.client.service.UserAddressReadService;
import com.wunong.smart.address.repository.UserAddressRepository;
import com.wunong.smart.domain.platform.rpc.Result;

import javax.annotation.Resource;
import java.util.List;

import static com.wunong.smart.address.converter.UserAddressDomainConverter.toDto;

/**
 * @author create by zealot.zt
 */
public class UserAddressReadServiceImpl implements UserAddressReadService {

    @Resource
    private UserAddressRepository userAddressRepository;

    @Override
    public Result<UserAddressDTO> getById(Long id) {
        return Result.create(toDto(userAddressRepository.getById(id)));
    }

    @Override
    public Result<UserAddressDTO> getById(Long userId, Long id) {
        return Result.create(toDto(userAddressRepository.getById(userId, id)));
    }

    @Override
    public Result<List<UserAddressDTO>> queryByUser(Long userId, Integer userRole) {
        return Result.create(toDto(userAddressRepository.queryByUser(userId, userRole)));
    }

    @Override
    public Result<UserAddressDTO> getDefaultAddress(Long userId, Integer userRole) {
        return Result.create(toDto(userAddressRepository.getDefaultAddress(userId, userRole)));
    }

    @Override
    public Result<List<UserAddressDTO>> query(Long userId, UserAddressQueryDTO query) {
        return Result.create(toDto(userAddressRepository.query(userId, query)));
    }

}
